package loppy.utils 
{
  public class InListIterator 
  {
    
    /** @private */
    internal var node:InListNode = null;
    
    /** @private */
    internal var list:InList = null;
    
    public function InListIterator(node:InListNode)
    {
      this.node = node;
      this.list = node.list;
    }
    
    public function isBegin():Boolean
    {
      return node == list.head.next;
    }
    
    public function isEnd():Boolean
    {
      return node == list.tail;
    }
    
    public function isRBegin():Boolean
    {
      return node == list.tail.prev;
    }
    
    public function isREnd():Boolean
    {
      return node == list.head;
    }
    
    public function hasNext():Boolean
    {
      return node.next != list.tail;
    }
    
    public function hasPrev():Boolean
    {
      return node.prev != list.head;
    }
    
    public function begin():InListIterator
    {
      node = list.head.next;
      return this;
    }
    
    public function end():InListIterator
    {
      node = list.tail;
      return this;
    }
    
    public function rbegin():InListIterator
    {
      node = list.tail.prev;
      return this;
    }
    
    public function rend():InListIterator
    {
      node = list.head;
      return this;
    }
    
    public function next():InListIterator
    {
      node = node.next;
      return this;
    }
    
    public function prev():InListIterator
    {
      node = node.prev;
      return this;
    }
    
    public function data():*
    {
      if (node != list.head && node != list.tail) return node;
      else return null;
    }
    
    public function remove():InListIterator
    {
      var next:InListNode = node.next;
      list.remove(node);
      node = next;
      return this;
    }
    
    public function clone():InListIterator
    {
      return new InListIterator(node);
    }
    
    public function copy(target:InListIterator):InListIterator
    {
      target.list = list;
      target.node = node;
      return this;
    }
  }
}